package com.sgb.kjwl.view.ui.fragment.shop;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentShopTdChildBinding;
import com.sgb.kjwl.di.shopping.DaggerShoppingFragComponent;
import com.sgb.kjwl.di.shopping.ShoppingFragModule;
import com.swgk.core.view.entity.MenuEntity;
import com.sgb.kjwl.viewmodel.shopping.ShopTdChildModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by WYJ on 2020/8/31.
 */
public class ShopTdChildFragment extends AppLazyFragment {

    public static final String SHOP_ID = "shop_id";

    @Inject
    ShopTdChildModel mModel;
    private FragmentShopTdChildBinding mBind;
    private ArrayList<Fragment> mFragments;

    public static ShopTdChildFragment newInstance(String shopId) {
        ShopTdChildFragment fragment = new ShopTdChildFragment();
        Bundle bundle = new Bundle();
        bundle.putString(SHOP_ID, shopId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBind = DataBindingUtil.inflate(inflater, R.layout.fragment_shop_td_child, container, false);
        return mBind.getRoot();
    }


    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerShoppingFragComponent.builder()
                .appComponent(appComponent)
                .shoppingFragModule(new ShoppingFragModule(ShopTdChildFragment.this))
                .build()
                .inject(this);
    }

    @Override
    protected void initView() {
        String shopId = getArguments().getString(SHOP_ID);
        mBind.setViewModel(mModel);
        mBind.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mBind.tabLayout.setupWithViewPager(mBind.vp);
        //teamInfo:工队列表
        //teamPublish:我的发布 -- 废弃
        //teamOffer:工种报价
        //teamAchieve:施工业绩
        //teamMember:工队人员
        //teamEquipment:自有设备
        List<MenuEntity> mTabs = new ArrayList<>();
        MenuEntity menu1 = new MenuEntity();
        MenuEntity menu2 = new MenuEntity();
        MenuEntity menu3 = new MenuEntity();
        MenuEntity menu4 = new MenuEntity();
        MenuEntity menu5 = new MenuEntity();
        MenuEntity menu6 = new MenuEntity();
        MenuEntity menu7 = new MenuEntity();
        //menu1.setId("teamInfo");
        //menu1.setName(getResources().getString(R.string.self_my_team));
        menu1.setId("teamInfo");
        menu1.setName(getResources().getString(R.string.self_team10));
        menu2.setId("teamOffer");
        menu2.setName(getResources().getString(R.string.self_team6));
        menu3.setId("teamAchieve");
        menu3.setName(getResources().getString(R.string.self_team7));
        menu4.setId("teamMember");
        menu4.setName(getResources().getString(R.string.self_team8));
        menu5.setId("teamEquipment");
        menu5.setName(getResources().getString(R.string.self_team2));
        //menu6.setId("teamAlbum");
        //menu6.setName(getResources().getString(R.string.self_team9));
        mTabs.add(menu1);
        mTabs.add(menu2);
        mTabs.add(menu3);
        mTabs.add(menu4);
        mTabs.add(menu5);
        //mTabs.add(menu6);
        //mTabs.add(menu7);

        mFragments = new ArrayList<>();
        String[] mTitles = new String[mTabs.size()];
        for (int i = 0; i < mTabs.size(); i++) {
            mTitles[i] = mTabs.get(i).getName();
            mFragments.add(ShopTdAchieveFragment.newInstance(shopId, mTabs.get(i).getId()));
           /* if (i == 0) {
                mFragments.add(ShopTdIntroFragment.newInstance(shopId, mTabs.get(i).getId()));
            } else {
                 mFragments.add(ShopTdAchieveFragment.newInstance(shopId, mTabs.get(i).getId()));
            }*/
        }
        SlidingFragmentPagerAdapter mPagerAdapter = new SlidingFragmentPagerAdapter(getChildFragmentManager(), mFragments, mTitles);
        mBind.vp.setOffscreenPageLimit(mTitles.length);
        mBind.vp.setAdapter(mPagerAdapter);
    }

    @Override
    protected void onLazyLoad() {

    }
}
